//
//  CarView.m
//  Exam12-1
//
//  Created by 孙晓晔 on 2017/4/22.
//  Copyright © 2017年 孙晓晔. All rights reserved.
//

#import "CarView.h"
#import "Car.h"

@interface CarView()
@property(nonatomic,strong) UIImageView *imageView;
@property(nonatomic,strong) UILabel *nameLabel;
@property(nonatomic,strong) UILabel *priceLabel;
@property(nonatomic,strong) UILabel *contentLabel;
@property(nonatomic,strong) UILabel *useLabel;

@end

@implementation CarView

-(void)setModel:(Car *)model {
    _model = model;
    
    _imageView.image = [UIImage imageNamed:model.pic];
    _nameLabel.text = model.name;
    //_priceLabel.text = [NSString stringWithFormat:@"¥%@元/天", model.price];
    _priceLabel.text = model.price;
    _contentLabel.text = model.content;
    _useLabel.text = [NSString stringWithFormat:@"%.0f%@接单", model.use * 100, @"%"];
    
    [self setNeedsDisplay];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:CGRectMake(5, 5, frame.size.width - 10, 90)]) {
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, frame.size.width*0.4 - 10, 70)];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
        
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 + frame.size.width*0.4 , 5, frame.size.width*0.3 - 5, 30)];
        [self addSubview:_nameLabel];
        
        _priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 + frame.size.width*0.7 , 5, frame.size.width*0.3 - 5, 30)];
        _priceLabel.font = [UIFont systemFontOfSize:13.f];
        
        [self addSubview:_priceLabel];
        
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 + frame.size.width*0.4 , 50, frame.size.width*0.3 - 5, 25)];
        _contentLabel.font = [UIFont systemFontOfSize:13.f];
        
        [self addSubview:_contentLabel];
        
        _useLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 + frame.size.width*0.7 , 50, frame.size.width*0.3 - 5, 25)];
        _useLabel.font = [UIFont systemFontOfSize:13.f];
        
        [self addSubview:_useLabel];
    }
    
    return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    
}*/

@end
